#!/usr/bin/env python
# cython: profile=True

import numpy as np
cimport numpy as np
cimport cython



def ftry(m1,m2,m3,m4,m5,m6,m7,m8):


	dim0,dim1=m1.shape
	
	cdef int i,j,k
	
	cdef np.ndarray[np.int_t, ndim=2,  mode="c"] mat0=np.zeros((dim0, dim1), dtype=np.int)
	
	
	for i in range(dim0):
		if i%100==0:print i,'iiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiii'
		for j in range(dim1):
			
			g=[ m1[i,j], m2[i,j], m3[i,j], m4[i,j], m5[i,j], m6[i,j], m7[i,j], m8[i,j] ]		
			
			#~ b0=g
			 #~ 
			b0=[g[0]]
			
				
			for k in range(1,8):
				if g[k]==0:
					b0.append(b0[k-1])
				if g[k]==1:
					if b0[k-1]==0:
						b0.append(1)
					if b0[k-1]==1:
						b0.append(0)


			mat0[i,j] = b0[0]*128 + b0[1]*64 + b0[2]*32 + b0[3]*16 + b0[4]*8 + b0[5]*4 + b0[6]*2 + b0[7]
			
			 
	return mat0
